#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.core.serializers.json import DjangoJSONEncoder
from django.http import JsonResponse

from ManageDaemon.view.ResultModel import ResultModel


class MyJsonResponse(JsonResponse):
    def __init__(self, data, encoder=DjangoJSONEncoder, safe=True, **kwargs):
        json_dumps_params = dict(ensure_ascii=False)
        super().__init__(data, encoder, safe, json_dumps_params, **kwargs)


def successResponse(msg,data=None):
    resultModel = ResultModel()
    resultModel.status = 0
    resultModel.message = msg
    resultModel.data=data
    return MyJsonResponse(resultModel.__dict__)

def errorDaemon(msg):
    resultModel = ResultModel()
    resultModel.status = 1000
    resultModel.message = msg
    return MyJsonResponse(resultModel.__dict__)

def errorResponse(msg):
    resultModel = ResultModel()
    resultModel.status = 1
    resultModel.message = msg
    return MyJsonResponse(resultModel.__dict__)
